package com.pignest.hotel.beans;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.pignest.hotel.annotation.Bean;
import com.pignest.hotel.beans.global.BaseBean;
import com.pignest.hotel.definition.RoomLiveStatus;
import com.pignest.hotel.definition.RoomRepairStatus;
import com.pignest.hotel.definition.RoomStatus;
import com.pignest.hotel.definition.RoomUseStatus;

@Bean("房间")
public class Room extends BaseBean {
	private static final long serialVersionUID = -6846430768461382501L;

	/** 房间号 */
	private String name;
	
	/** 房间类型 */
	private RoomType type;
	
	/** 使用状态 */
	private String useStatus;
	
	/** 入住状态 */
	private String liveStatus;
	
	/** 维修状态 */
	private String repairStatus;
	
	/** 分店 */
	private String branchStore;
	
	/** 楼 */
	private String building;
	
	/** 层 */
	private String floor;
	
	/** 房间电话号码 */
	private String phoneNumber;
	
	/** 备注 */
	private String remark;
	
	private boolean selfHelp;
	
	private String lockNumber;
	
	/** 房间特征, 暂时保存房间的色调, 如果不设置, 则取房间类型的颜色 */
	private String color;
	
	/** 最后的清理时间 */
	private Date lastCleanTime;
	
	///////////////////////////////////////////////////////////////////////
	
//	//当前入住单号
//	private String serialNumber;
	
	public Room() {
	}
	
	public Room(String name, RoomType type, String floor) {
		this.name = name;
		this.type = type;
		this.floor = floor;
		this.useStatus = RoomUseStatus.CLEAN.name();
		this.liveStatus = RoomLiveStatus.EMPTY.name();
		this.repairStatus = RoomRepairStatus.NORMAL.name();
		this.lockNumber = name;
	}
	
	public Room(String name, RoomType type, String floor, String color, String lockNumber) {
		this.name = name;
		this.type = type;
		this.floor = floor;
		this.useStatus = RoomUseStatus.CLEAN.name();
		this.liveStatus = RoomLiveStatus.EMPTY.name();
		this.repairStatus = RoomRepairStatus.NORMAL.name();
		this.color = color;
		this.lockNumber = lockNumber != null ? lockNumber : name;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUseStatus() {
		return useStatus;
	}
	public void setUseStatus(String status) {
		this.useStatus = status;
	}
	public String getBranchStore() {
		return branchStore;
	}
	public void setBranchStore(String branchStore) {
		this.branchStore = branchStore;
	}
	public RoomType getType() {
		return type;
	}
	public void setType(RoomType type) {
		this.type = type;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public String getFloor() {
		return floor;
	}
	
	public void setFloor(String floor) {
		this.floor = floor;
	}
	
	public void setBuilding(String building) {
		this.building = building;
	}
	
	public String getBuilding() {
		return building;
	}
	
	public String getLiveStatus() {
		return liveStatus;
	}
	
	public void setLiveStatus(String liveStatus) {
		this.liveStatus = liveStatus;
	}
	
	public String getRepairStatus() {
		return repairStatus;
	}
	
	public void setRepairStatus(String repairStatus) {
		this.repairStatus = repairStatus;
	}
	
	public String getPhoneNumber() {
		return phoneNumber;
	}
	
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public boolean isSelfHelp() {
		return selfHelp;
	}
	public void setSelfHelp(boolean selfHelp) {
		this.selfHelp = selfHelp;
	}
	
	public String getColor() {
		return color;
	}
	
	public void setColor(String feature) {
		this.color = feature;
	}
	
	public Date getLastCleanTime() {
		return lastCleanTime;
	}
	
	public void setLastCleanTime(Date lastCleanTime) {
		this.lastCleanTime = lastCleanTime;
	}
	
///////////////////////////////////////////////////////////////////////////////
	
	public String getColor2() {
		if (StringUtils.isNotEmpty(color))
			return color;
		if (type != null)
			return type.getColor();
		return null;
	}
	
	public void setRoomLiveStatus(RoomLiveStatus liveStatus) {
		this.liveStatus = liveStatus.name();
	}
	
	public void setRoomUseStatus(RoomUseStatus useStatus) {
		this.useStatus = useStatus.name();
		if (useStatus == RoomUseStatus.CLEAN)
			lastCleanTime = new Date();
	}
	
	public void setRoomRepairStatus(RoomRepairStatus repairStatus) {
		this.repairStatus = repairStatus.name();
	}
	
	public RoomStatus getRoomStatus() {
		return new RoomStatus(this);
	}
	
	public void setRoomStatus(RoomStatus status) {
		//TODO
	}
	
	public String getUseStatusImage() {
		RoomUseStatus use = RoomUseStatus.valueOf(useStatus);
		if (use == null)
			return null;
		return use.getImage();
	}
	
	public String getLiveStatusImage() {
		RoomLiveStatus live = RoomLiveStatus.valueof(liveStatus);
		if (live == null)
			return null;
		return live.getImage();
	}
	
	public String getRepairStatusImage() {
		RoomRepairStatus repair = RoomRepairStatus.valueof(repairStatus);
		if (repair == null)
			return null;
		return repair.getImage();
	}
	
	public String getLockNumber() {
		return lockNumber;
	}
	public void setLockNumber(String lockNumber) {
		this.lockNumber = lockNumber;
	}
	@Override
	public String toString() {
		return name;
	}
	
	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Room)
			return StringUtils.equals(name, ((Room)obj).name);
		return false;
	}
	
///////////////////////////////////////////////////////////////////////////////
	
	@Override
	public String toSimpleString() {
		return concat(name, type.getName());
	}
}
